<?php
/**
 * quick_curd
 * ============================================================================
 * 版权所有 2024-2099 wltx666.com，并保留所有权利。
 * 网站地址: https://wltx666.com
 * ============================================================================
 * Author: 草上飞
 * Email: wltx@alipay168.cn
 * QQ: 2719875001
 * Date: 2025/1/3
 * 描述:
 */

namespace lib\exception;

use think\exception\Handle;
use think\exception\HttpException;
use think\exception\ValidateException;
use think\Response;
use Throwable;

class Http extends Handle
{
    public function render($request, Throwable $e): Response
    {
        bs_log([
            'code' => $e->getCode(),
            'msg' => $e->getMessage(),
            'file' => $e->getFile(),
            'line' => $e->getLine(),
            'type' => get_class($e)
            //'trace'=> $e->getTraceAsString()
        ], 'exception', 'error.log');
        if (config('app.app_debug')) {
             return parent::render($request, $e);
        }

        if ($e->getCode() == 403) {
            return Response::create('无权访问', 'json', 403);
        } elseif ($e->getCode() == 401) {
            return Response::create('登录过期', 'json', 401);
        } elseif ($e->getCode() == 404) {
            return Response::create('未找到该页面', 'json', 404);
        } elseif ($e->getCode() == 500) {
            return Response::create('系统服务忙碌中，请稍后再试！', 'json', 500);
        }


        // 其他错误交给系统处理
        return parent::render($request, $e);
    }

}
